<?php

/** Yz_Int:

*/

class Yz_Int extends Yz_Type
{

    /**
    *   @var int
    */
    protected $value;

    protected static $expects = array(
        'test'                => 'number',
        'testNotNegative'     => 'non-negative number',
        'testPositive'        => 'positive number',
    );


    /** valueOf(): reduce the value to string
    *       Objects which have toString() do not count
    *   @param scalar value
    *   @return string|null
    */
    public static function valueOf( $value )
    {
        $pValue = null;
        if (is_scalar($value) && is_numeric($value)) { // "null" is not considered scalar
            $pValue = (int)$value;
        }

        return $pValue;
    } // valueOf


    public static function testNotNegative( $value, $context=null )
    {
        return static::doTest( $value, $context, 'testNotNegative', function( $val ) {
            return $val >= 0;
        } );
    }


    public static function testPositive( $value, $context=null )
    {
        return static::doTest( $value, $context, 'testPositive', function( $val ) {
            return $val > 0;
        } );
    }

} // class

